# Contributor: Daniel Everett <deverett@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=yubikey-manager
pkgver=5.5.1
pkgrel=0
pkgdesc="Python library and command line tool for configuring any YubiKey over all USB interfaces"
url="https://developers.yubico.com/yubikey-manager/"
arch="noarch"
license="BSD-2-Clause"
depends="
	ccid
	pcsc-lite
	pcsc-lite-libs
	py3-click
	py3-cryptography
	py3-fido2
	py3-keyring
	py3-pyscard
	py3-ykman
	python3
	yubico-c
	"
makedepends="
	py3-poetry-core
	py3-gpep517
	bash
	"
checkdepends="py3-pytest py3-makefun"
subpackages="
	$pkgname-pyc
	py3-ykman
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/Yubico/yubikey-manager/releases/download/$pkgver/yubikey_manager-$pkgver.tar.gz"
builddir="$srcdir/yubikey_manager-$pkgver"

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	.testenv/bin/python3 -m pytest
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl

	install -dm755 "$pkgdir/usr/share/zsh/site-functions/" \
		"$pkgdir/usr/share/bash-completion/completions/" \
		"$pkgdir/usr/share/fish/vendor_completions.d/"

	local _pypkgs=$(python -c 'import site; print(site.getsitepackages()[0])')
	PYTHONPATH="$pkgdir$_pypkgs/" _YKMAN_COMPLETE=zsh_source "$pkgdir/usr/bin/ykman" > \
		"$pkgdir/usr/share/zsh/site-functions/_ykman"
	PYTHONPATH="$pkgdir$_pypkgs/" _YKMAN_COMPLETE=bash_source "$pkgdir/usr/bin/ykman" > \
		"$pkgdir/usr/share/bash-completion/completions/ykman"
	PYTHONPATH="$pkgdir$_pypkgs/" _YKMAN_COMPLETE=fish_source "$pkgdir/usr/bin/ykman" > \
		"$pkgdir/usr/share/fish/vendor_completions.d/ykman.fish"
}

ykman() {
	depends=
	amove usr/lib
}

sha512sums="
67e2e5a5833f746441d91684a5b0889bd9b9b46aeaee0da875c7e6dac46db619a8436e12bd77c38e525121db8fc52736071bc141ac80c6d79e64919e100510f9  yubikey_manager-5.5.1.tar.gz
"
